Add mean() to borrowed CumulativeRO Ref views#21
Merged
Conversation
Exposes a public, non-allocating mean() on CumulativeROHistogramRef and CumulativeROHistogram32Ref so a zero-alloc streaming reducer holding a borrowed Ref can fold the midpoint-based mean in directly. The owned type caches the mean at construction; the borrowed view computes it from the borrowed slices on each call. https://claude.ai/code/session_01LDxW544z6m39mY9SkMh9XD
Expose mean() as a cheap field access on the borrowed Ref views, mirroring count(), instead of streaming the midpoint computation on every call. The owned type's as_ref()/From impls pass their already-cached mean through, so the hot path does no recomputation; slice-only constructors compute it once. The Ref types now carry an f64 and so no longer derive Eq (PartialEq kept). https://claude.ai/code/session_01LDxW544z6m39mY9SkMh9XD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mean()to the borrowedCumulativeROHistogramRef<'a>andCumulativeROHistogram32Ref<'a>views.Reffold the mean in directly without materializing an owned histogram.Nonefor an empty histogram, matching the ownedmean().Versioning
Per
CLAUDE.md, this feature PR bumps to1.5.0-alpha.1(additive public API → minor bump over the 1.4.0 release commit in this branch's lineage). CHANGELOG updated under[Unreleased].Test plan
cargo test --lib— 118 passedcargo clippy --lib— cleanref_mean_parity_u64,ref_mean_parity_u32,ref_mean_empty_is_none(owned vs. borrowed agreement, empty →None)https://claude.ai/code/session_01LDxW544z6m39mY9SkMh9XD
Generated by Claude Code